qui(
    function (require, exports, module) {
        Director.Edit = function (options) {
            this.dao = Director.Dao;
            this.config = Director.Config;
            this.task = Director.Task;
            this.options = options || {};
        };
        Com.inherits(Director.Edit, function () {
        }).extend({
            init: function () {
                var self = this;
                var param_id = Com.url.getParameter("programQipuId");
                if (param_id == null || !param_id.endsWith("23")) {
                    console.log("no such data");
                    return
                }
                var taskArr = self.getInitTaskArr();
                $.each(taskArr, function (index, element) {
                    EpgWeb.ajaxQueue.push(element.regName, element.options);
                })
                EpgWeb.ajaxQueue.afterLoadComplete(function () {
                    var entity = Director.Util.getEntity();
                    self.config.ImgLogo = $('<img id="imgLogo" src="img/u743.png" >');
                    self.config.ImgLogoMainResource = $('<img id="imgLogo_mainResource" src="img/u743.png" >');
                    if (entity != null) {
                        Director.Model.initCountDownTimer(entity);
                        Director.Util.initDetailZone(entity);
                        self.fillNavBar();
                        self.config.PageBeanResource = Director.Util.createPageBean();
                        self.config.PageBeanBackup = Director.Util.createPageBean();
                        self.initDialog();
                        self.bindEvent();
                        self.initSuggest();
                        self.initPlayerZone();
                        Director.Player.initPlayer();
                        Director.Player.setCurResourceId(entity.resourceId);
                        Director.Util.getResourceList();
                        Director.Util.getBackUpList();
                        self.setProgramPageUrl(param_id);

                        // 特效相关
                        self.config.PageBeanEffectImage = Director.Util.createPageBean();
                        self.config.PageBeanEffectSubtitle = Director.Util.createPageBean();
                        self.config.PageBeanEffectAnimation = Director.Util.createPageBean();
                        self.config.PageBeanEffectAudio = Director.Util.createPageBean();
                        self.config.PageBeanEffectCover = Director.Util.createPageBean();
                        Director.Util.getEffectList(1);
                        Director.Util.getEffectList(2);
                        Director.Util.getEffectList(3);
                        Director.Util.getEffectList(4);
                        Director.Util.getEffectList(5);

                        self.bindEffectEvent();

                        //解说相关
                        //Director.Commentary.getCommentaryList(false);
                    }
                })
                EpgWeb.ajaxQueue.startLoad();
            },

            getInitTaskArr: function () {
                var taskArr = [];
                var param_id = Com.url.getParameter("programQipuId");
                taskArr.push({
                    regName: "entity",
                    options: {
                        type: "post",
                        url: Director.urlConfig.listUrl,
                        dataType: "json",
                        data: {qipuId: param_id, fullMode: "true"}
                    }
                });
                return taskArr;
            },


            fillNavBar: function () {
                // var navDiv = $("#navDiv");
                // navDiv.tabs({active: 0});
            },
            initDialog: function () {
                var self = this;
                $("#dlg_preview").dialog({
                    title: "预览",
                    autoOpen: false,
                    width: 500,
                    modal: true,
                    dialogClass: 'alert',
                    resizable: false,
                    buttons: [
                        {
                            text: "关闭",
                            click: function () {
                                $("#dlg_preview").find("object").remove();
                                $(this).dialog("close");
                            }
                        }
                    ]
                });
                $("#dlg_settings").dialog({
                    title: "设置",
                    autoOpen: false,
                    width: 500,
                    modal: true,
                    dialogClass: 'alert',
                    resizable: false,
                    buttons: [
                        {
                            text: "确定",
                            click: function () {
                                Director.Util.submitEditDirector();
                                $(this).dialog("close");
                            }
                        },
                        {
                            text: "取消",
                            click: function () {
                                $(this).dialog("close");
                            }
                        }
                    ]
                });
                $("#dlg_add_alternatePlay").dialog({
                    title: "添加灾备",
                    autoOpen: false,
                    width: 720,
                    height: 400,
                    modal: true,
                    dialogClass: 'alert',
                    resizable: false,
                    buttons: [
                        {
                            text: "确定",
                            click: function () {
                                if (Director.Util.submitAddBackUp()) {
                                    $("label[name=hint-id]").html("");
                                    $(this).dialog("close");
                                }
                            }
                        },
                        {
                            text: "取消",
                            click: function () {
                                $("label[name=hint-id]").html("");
                                $(this).dialog("close");
                            }
                        }
                    ]
                });
                $("#dlg_add_signal").dialog({
                    title: "添加信号源",
                    autoOpen: false,
                    width: 720,
                    height: 400,
                    modal: true,
                    dialogClass: 'alert',
                    resizable: false,
                    buttons: [
                        {
                            text: "确定",
                            click: function () {
                                if (Director.Util.submitAddSignal()) {
                                    $("label[name=hint-id]").html("");
                                    $(this).dialog("close");
                                }
                            }
                        },
                        {
                            text: "取消",
                            click: function () {
                                $("label[name=hint-id]").html("");
                                $(this).dialog("close");
                            }
                        }
                    ]
                });
                $("#dlg_edit_image").dialog({
                    title: "动画编辑",
                    autoOpen: false,
                    width: 560,
                    height: 450,
                    modal: true,
                    dialogClass: 'alert',
                    resizable: false,
                    buttons: [
                        {
                            text: "确定",
                            click: function () {
                                if (Director.Util.submitEditEffect(1)) {
                                    $(this).dialog("close");
                                }
                            }
                        },
                        {
                            text: "取消",
                            click: function () {
                                $("label[name=hint-id]").html("");
                                $(this).dialog("close");
                            }
                        }
                    ]
                });
                $("#dlg_edit_subtitle").dialog({
                    title: "字幕编辑",
                    autoOpen: false,
                    width: 620,
                    height: 450,
                    modal: true,
                    dialogClass: 'alert',
                    resizable: false,
                    buttons: [
                        {
                            text: "确定",
                            click: function () {
                                if (Director.Util.submitEditEffect(2)) {
                                    $(this).dialog("close");
                                }
                            }
                        },
                        {
                            text: "取消",
                            click: function () {
                                $(this).dialog("close");
                            }
                        }
                    ]
                });
                $("#dlg_edit_animation").dialog({
                    title: "动画编辑",
                    autoOpen: false,
                    width: 620,
                    height: 450,
                    modal: true,
                    dialogClass: 'alert',
                    resizable: false,
                    buttons: [
                        {
                            text: "确定",
                            click: function () {
                                if (Director.Util.submitEditEffect(3)) {
                                    $(this).dialog("close");
                                }
                            }
                        },
                        {
                            text: "取消",
                            click: function () {
                                $("label[name=hint-id]").html("");
                                $(this).dialog("close");
                            }
                        }
                    ]
                });
                $("#dlg_edit_cover").dialog({
                    title: "遮标编辑",
                    autoOpen: false,
                    width: 620,
                    height: 450,
                    modal: true,
                    dialogClass: 'alert',
                    resizable: false,
                    buttons: [
                        {
                            text: "确定",
                            click: function () {
                                if (Director.Util.submitEditEffect(5)) {
                                    $(this).dialog("close");
                                }
                            }
                        },
                        {
                            text: "取消",
                            click: function () {
                                $("label[name=hint-id]").html("");
                                $(this).dialog("close");
                            }
                        }
                    ]
                });
                $(".ui-dialog-titlebar-close").html('<span class="ui-button-icon-primary ui-icon ui-icon-closethick"></span><span class="ui-button-text">close</span>');
                var btnCls1Arr = "dlg_preview,dlg_settings,dlg_add_alternatePlay,dlg_add_signal,dlg_edit_image,dlg_edit_subtitle,dlg_edit_animation,dlg_edit_cover".split(",");
                $.each(btnCls1Arr, function (i, element) {
                    $("div[aria-describedby=" + element + "]").find("div.ui-dialog-buttonset").find("button:eq(0)").addClass("btn-primary");
                    $("div[aria-describedby=" + element + "]").find("div.ui-dialog-buttonset").find("button").addClass("btn");
                })
                $("button[name=query_system_preview_url]").on("click", function (event) {
                    Director.Util.quickCreatePreviewUrl( )
                })
            },

            bindEvent: function () {
                var self = this;
                $("button[name=changeBtn]").bind("click", function (event) {
                    var currentTarget = $(event.currentTarget);
                    if (currentTarget.attr("data-key") == "switchBackUp") {
                        Director.Util.switchBackUp();
                    }
//                    else if(currentTarget.attr("data-key") == "recoverDelay"){
//                        Director.Util.recoverDelay();
//                    }
                })


                $("a[name=preview_link]").bind("click", function (event) {
                    if (Director.Config.DURING_CHANGE_SETTINGS) {
                        SystemDialog.queryAlert("正在切换设置，请稍后操作");
                        return;
                    }
                    //$("#dlg_preview").html('<div id="flv_preview" style="width:480px;height: 270px;background-color:black;color:white;"></div>');
                    //Director.Player.createPreview();
                    //$("#dlg_preview").dialog("open");
                    $('#flv_preview_container').html('<div id="flv_preview_foreground" style="width:410px;height:255px;background-color:black;color:white;"></div>');
                    $('#director_detail_player').css('z-index', 1);
                    Director.Player.createFlvPreview();
                })

                $("button[name=closePreview]").bind("click", function (e) {
                    $('#director_detail_player').css('z-index', -1);
                    $('#flv_preview_container').html('');
                });

                $("button[name=btn_settings]").bind("click", function (event) {
                    var entity = Director.Util.getEntity();
                    if (Director.Config.DURING_CHANGE_SETTINGS) {
                        SystemDialog.queryAlert("正在切换设置，请稍后操作");
                        return;
                    }
                    self.initSettings(entity.startPlayTime < EpgWeb.Util.formatDateTimeFormat(new Date()));
                })
                var self = this;
                var signalParent = $("#dlg_add_signal");
                signalParent.find("select[name=signal_type]").bind("change", function (event) {
                    var $curTarget = $(event.currentTarget);
                    var selectedValue = $curTarget.val();
                    self.defaultSignalView(signalParent);
                    signalParent.find("input[name=signal_url_" + selectedValue + "]").show();
                    if (selectedValue === "2") {
                        //$("#signal_preview_div").show();
                    //    $("button[name=query_system_preview_url]").css('display', 'inline-block');
                    }
                    if (selectedValue === "0" || selectedValue === "2") {
                        signalParent.find("#div_set_main_resource").show();
                        var resources = Director.Config.PageBeanResource.getSource().length;
                        var director = Director.Util.getEntity();
                        if (resources > 0 && director.mainResourceId != 0) {
                            signalParent.find("input[name=set_main_resource]").removeAttr("checked");
                        }
                    } else {
                        signalParent.find("#div_set_main_resource").hide();
                    }
                })
            },
            initSettings: function (isStarted) {
                var parent = $("#dlg_settings");
                parent.dialog("open");
                var entity = Director.Util.getEntity();
                parent.find("input[name=input_out_url]").val(entity.outputUrl);
                parent.find("input[name=delay]").val(entity.delay);
                parent.find("select[name=stream_type]").val(entity.outputStreamType);
                if (isStarted) {
                    parent.find("input[name=delay]").prop("disabled", "disabled");
                    parent.find("select[name=stream_type]").prop("disabled", "disabled")
                } else {
                    parent.find("input[name=delay]").removeAttr("disabled");
                    parent.find("select[name=stream_type]").removeAttr("disabled")
                }
            },
            initPlayerZone: function () {
                Director.Util.initDefaultResourceZone();
                Director.Util.initDefaultBackupZone();

                //Director.Util.initEffectZone();
            },
            initSuggest: function () {
                var playbackSuggest = {
                    id: "playbackSuggest",
                    options: {
                        source: EpgWeb.urlConfig.redirect,
                        method: "post",
                        multiple: false,
                        parseValue: function () {
                            var val = this.element.val(),
                                ret = []
                            return ret;
                        },
                        select: function (event, object) {
                            $("label[name=hint-id]").html("奇谱ID:" + object.item.qipuId + ";乐高Id:" + object.item.entityId);
                            return true;
                        },
                        getParam: function (term) {
                            $("label[name=hint-id]").html("");
                            var requestData = {
                                url: EpgWeb.Constant.thirdUrl_video_url,
                                type: "get",
                                params: {word: term, type: "properTitle"},
                                needCookie: true
                            };
                            return {"request": JSON.stringify(requestData), timeSign: new Date().getTime()}
                        },

                        process: function (json) {
                            var ret = [],
                                self = this,
                                options = self.options,
                                itemData = null;
                            var data = null;
                            if (json == null) {
                                return [];
                            }
                            if (json.code === "A00000") {
                                data = $.isArray(json) ? json : json.data;
                            }
                            if (!data) {
                                return [];
                            }

                            $.map(data, function (item) {
                                if (item["qipuId"] == null || item["qipuId"] == 0) {
                                    return true;
                                }
                                itemData = {};
                                itemData[options.valueKey] = item["qipuId"];
                                itemData[options.labelKey] = item["properTitle"];
                                itemData[self._displayKey] = item["entityId"];
                                itemData["entityId"] = item["entityId"];
                                itemData["qipuId"] = item["qipuId"];
                                itemData["channelName"] = item["channelName"];
                                ret.push(itemData);
                            });
                            return ret;
                        },

                        template: function (item) {
                            var formatArr = [];
                            formatArr.push('<span class="contract-width100">' + item["entityId"] + '</span>');
                            formatArr.push('<span class="contract-width100">' + item["qipuId"] + '</span>');
                            formatArr.push('<span class="contract-width150">' + item["label"] + '</span>');
                            formatArr.push('<span class="contract-width60">' + item["channelName"] + '</span>');
                            return '<div class="contract-item" >' + formatArr.join("") + '</div>';
                        },
                        header: '<div class="contract-item" >' +
                            '<span class="contract-width100">节目Id</span>' +
                            '<span class="contract-width100">节目qipuId</span>' +
                            '<span class="contract-width150">节目显示名称</span>' +
                            '<span class="contract-width60">频道</span>' +
                            '</div>'
                    }
                };

                var liveSuggest = {
                    id: "liveSuggest",
                    options: {
                        source: EpgWeb.urlConfig.programList,
                        method: "post",
                        multiple: false,
                        ajaxSettings: {
                            beforeSend: function (request) {
                                var authBase = Ancestor.Util.getAuth("/program/list");
                                request.setRequestHeader('Sign', authBase.sign);
                                request.setRequestHeader("Time", authBase.clientTime);
                                request.setRequestHeader("From", authBase.from);
                                request.setRequestHeader("UserName", (auth.baseInfo.authInfo == null) ? "" : escape(auth.baseInfo.authInfo.userName).toLocaleLowerCase().replace(/%u/gi, '\\u'));
                            }
                        },
                        select: function (event, object) {
                            //   this.value = object.item.id + "";
                            //  return false;
                            $("label[name=hint-id]").html("奇谱ID:" + object.item.id);
                            return true;
                        },
                        parseValue: function () {
                            var val = this.element.val(),
                                ret = []
                            return ret;
                        },
                        getParam: function (term) {
                            $("label[name=hint-id]").html("");
                            return {liveType: 2, fromPath: "library", deleteStatus: 0, pname: term}
                        },

                        process: function (json) {
                            var ret = [],
                                self = this,
                                options = self.options,
                                itemData = null;
                            var data = null;
                            if (json == null) {
                                return [];
                            }
                            if (json.code === "A00000") {
                                data = json.data.result;
                            }
                            if (!data) {
                                return [];
                            }

                            $.map(data, function (item) {
                                if (item["qipuId"] == null || item["qipuId"] == 0) {
                                    return true;
                                }
                                itemData = {};
                                itemData[options.valueKey] = item["qipuId"];
                                itemData[options.labelKey] = item["pname"];
                                itemData[self._displayKey] = item["qipuId"];
                                itemData["channelName"] = item["channelName"];
                                itemData["startPlayTime"] = item["startPlayTime"]
                                itemData["endPlayTime"] = item["endPlayTime"]
                                ret.push(itemData);
                            });
                            return ret;
                        },
                        template: function (item) {
                            var formatArr = [];
                            formatArr.push('<span class="contract-width100">' + item["id"] + '</span>');
                            formatArr.push('<span class="contract-width150">' + item["label"] + '</span>');
                            formatArr.push('<span class="contract-width60">' + item["channelName"] + '</span>');
                            formatArr.push('<span class="contract-width100">' + item["startPlayTime"] + '</span>');
                            formatArr.push('<span class="contract-width100">' + item["endPlayTime"] + '</span>');
                            return '<div class="contract-item" >' + formatArr.join("") + '</div>';
                        },
                        header: '<div class="contract-item" >' +
                            '<span class="contract-width100">节目Id</span>' +
                            '<span class="contract-width150">节目显示名称</span>' +
                            '<span class="contract-width60">频道</span>' +
                            '<span class="contract-width100">开始时间</span>' +
                            '<span class="contract-width100">结束时间</span>' +
                            '</div>'
                    }
                }
                $("input[name=signal_url_1]").suggest(playbackSuggest.options);
                $("input[name=signal_url_0]").suggest(liveSuggest.options);
            },
            defaultSignalView: function (parent) {
                parent.find("input[name^=signal_url_]").hide();
                $("#signal_preview_div").hide();
                parent.find("label[name=hint-id]").html("");
                parent.find("button[name=query_system_preview_url]").hide();
            },

            queryResource: function () {
                console.log("queryResource ");
                //$("#tabPanel_1").html();
            },
            queryBackUpResource: function () {
                console.log("queryBackUpResource ")
            },

            bindEffectEvent: function () {
                var self = this;
                var $imageArea = $("#effect-tabs-1"),
                    $subtitleArea = $("#effect-tabs-2"),
                    $animationArea = $("#effect-tabs-3"),
                    $audioArea = $("#effect-tabs-4");

                var $imageUploadBtn = $imageArea.find("input.uploadBtn");
                var imageParent = $("#dlg_edit_image");
                $imageUploadBtn.val("");
                $imageUploadBtn.bind("click", function (event) {
                    console.log("click");
                });
                $imageUploadBtn.bind("change", function (e) {
                    var file = e.target.files[0];
                    var url = Com.file.getObjectURL(file)

                    var params = self.config.EffectUploadCommonParams;

                    params.business_type = "image";
                    params.file_type = Com.file.getExt(file.name);
                    params.file_size = file.size;

                    params.file = file;

                    $(this).val('');
                    // 判断上传素材是否是图片
                    if (!Director.Util.isValidImage(params.file_type)) {
                        EpgWeb.Plugin.showTips({content: "上传图片格式只支持png, jpg, bmp, gif, 请重新上传", type: "error"})
                        return;
                    }


                    self.startUploadFile(params, self.AddEffectImage);

                });

                var loopCheckbox = imageParent.find('input[name=loop]');
                loopCheckbox.bind('change', function (e) {
                    var target = $(e.target);
                    var loopDiv = imageParent.find('#effect-image-loop-div');
                    if (target.is(":checked")) {
                        loopDiv.show();
                    } else {
                        loopDiv.hide();
                    }
                });

                var imageAnmiationSelect = imageParent.find('select[name=animation]');
                imageAnmiationSelect.bind('change', function (e) {
                    var target = $(e.target);
                    var timesDiv = imageParent.find('#effect-image-times-div');
                    if (target.val() == "0") {
                        timesDiv.hide();
                    } else {
                        timesDiv.show();
                    }
                });

                //imageAnmiationSelect.click();

                var $subtitleAddBtn = $subtitleArea.find("button.btnAdd");
                $subtitleAddBtn.bind("click", function (e) {
                    Director.Util.AddSubtitleShow();
                });

                var subtitleParent = $('#dlg_edit_subtitle');
                var uploadSubtitleButton = subtitleParent.find('input.uploadBtn');
                uploadSubtitleButton.bind("change", function (e) {
                    var file = e.target.files[0];
                    var url = Com.file.getObjectURL(file)

                    var params = Director.Config.EffectUploadCommonParams;

                    params.business_type = "image";
                    params.file_type = Com.file.getExt(file.name);
                    params.file_size = file.size;

                    params.file = file;

                    $(this).val('');
                    // 判断上传素材是否是图片
                    if (!Director.Util.isValidImage(params.file_type)) {
                        EpgWeb.Plugin.showTips({content: "上传图片格式只支持png, jpg, bmp, gif, 请重新上传", type: "error"})
                        return;
                    }

                    var img = new Image();
                    img.onload = function () {
                        if (img.width != 1920 || img.height != 70) {
                            EpgWeb.Plugin.showTips({content: "只支持1920X70的图片，请重新上传", type: "error"})
                        } else {
                            self.startUploadFile(params, Director.Util.AddSubtitleBackground);
                        }
                    }

                    img.src = url;

                });

                //subtitleParent.find('textarea[name=content]').keydown(function(e) {
                //    var textarea = $(e.target);
                //
                //    if (e.keycode == 13) {
                //        e.returnValue = false;
                //        e.preventDefault();
                //    }
                //
                //    if(Com.string.getStrLength(textarea.val()) > 200 * 2) {
                //        textarea.val(textarea.val().substring(0, 200));
                //    }
                //})

                var subtitleEffectChangeList = ['select[name=fontName]', 'select[name=fontSize]', 'input[name=fontColor]'];
                $.each(subtitleEffectChangeList, function (i, e) {
                    subtitleParent.find(e).bind("change", function () {
                        Director.Util.dialogSubtitlePreview();
                    })
                });

                //var fontArrays = ['fontBold', 'fontItalic', 'fontUnderline'];
                var fontArrays = ['fontBold'];
                $.each(fontArrays, function (i, e) {
                    var a = subtitleParent.find('a.' + e);
                    a.bind('click', function (event) {
                        $(this).toggleClass('active');
                        $(this).find('input').val($(this).hasClass('active') ? 1 : 0);
                        Director.Util.dialogSubtitlePreview();
                    })
                });

                var subtitleLoopCheckbox = subtitleParent.find('input[name=loop]');
                subtitleLoopCheckbox.bind('change', function (e) {
                    var target = $(e.target);
                    var loopDiv = subtitleParent.find('#effect-subtitle-loop-div');
                    if (target.is(":checked")) {
                        loopDiv.show();
                    } else {
                        loopDiv.hide();
                    }
                });

                var subtitleHorseCheckbox = subtitleParent.find('input[name=horseLamp]');
                subtitleHorseCheckbox.bind('change', function (e) {
                    var target = $(e.target);
                    var loopDiv = subtitleParent.find('#effect-subtitle-loop-container-div');
                    if (target.is(":checked")) {
                        loopDiv.show();
                    } else {
                        loopDiv.hide();
                    }
                });

                var $animationAddBtn = $animationArea.find("button.btnAdd");
                $animationAddBtn.bind("click", function (e) {
                    Director.Util.AddAnimationShow();
                });
                var animationParent = $('#dlg_edit_animation');
                var uploadAUrlBtn = animationParent.find('input.uploadBtnUrl');
                var uploadAForegroundBtn = animationParent.find('input.uploadBtnForeground');
                uploadAUrlBtn.bind("change", function (e) {
                    var file = e.target.files[0];
                    var url = Com.file.getObjectURL(file)

                    var params = Director.Config.EffectUploadCommonParams;

                    params.business_type = "video";
                    params.file_type = Com.file.getExt(file.name);
                    params.file_size = file.size;

                    params.file = file;

                    $(this).val('');
                    // 判断上传素材是否是视频
                    if (!Director.Util.isValidVideo(params.file_type)) {
                        EpgWeb.Plugin.showTips({content: "上传动画格式只支持mov, 请重新上传", type: "error"})
                        return;
                    }

                    self.startUploadFile(params, Director.Util.AddAnimationUrl);
                });

                uploadAForegroundBtn.bind("change", function (e) {
                    var file = e.target.files[0];
                    var url = Com.file.getObjectURL(file)

                    var params = Director.Config.EffectUploadCommonParams;

                    params.business_type = "image";
                    params.file_type = Com.file.getExt(file.name);
                    params.file_size = file.size;

                    params.file = file;

                    $(this).val('');
                    // 判断上传素材是否是图片
                    if (!Director.Util.isValidImage(params.file_type)) {
                        EpgWeb.Plugin.showTips({content: "上传图片格式只支持png, jpg, bmp, gif, 请重新上传", type: "error"})
                        return;
                    }

                    self.startUploadFile(params, Director.Util.AddAnimationForeground);
                });

                var animationLoopCheckbox = animationParent.find('input[name=loop]');
                animationLoopCheckbox.bind('change', function (e) {
                    var target = $(e.target);
                    var loopDiv = animationParent.find('#effect-animation-loop-div');
                    if (target.is(":checked")) {
                        loopDiv.show();
                    } else {
                        loopDiv.hide();
                    }
                });

                var $audioUploadBtn = $audioArea.find("input.uploadBtn");
                $audioUploadBtn.val('');
                $audioUploadBtn.bind("click", function (event) {
                    console.log("click");
                });
                $audioUploadBtn.bind("change", function (e) {
                    var file = e.target.files[0];
                    var url = Com.file.getObjectURL(file)

                    var params = self.config.EffectUploadCommonParams;

                    params.business_type = "audio";
                    params.file_type = Com.file.getExt(file.name);
                    params.file_size = file.size;

                    params.file = file;

                    $(this).val('');
                    // 判断上传素材是否是音频
                    if (!Director.Util.isValidAudio(params.file_type)) {
                        EpgWeb.Plugin.showTips({content: "上传音频格式只支持mp3, 请重新上传", type: "error"})
                        return;
                    }

                    self.startUploadFile(params, self.AddEffectAudio);

                });

                //$(window).keydown(function(e) {
                //    if(e.ctrlKey) {
                //        Director.Config.EFFECT_CTRL_KEYDOWN = true;
                //        //console.log("CTRL keydown")
                //    }
                //}).keyup(function(){
                //    Director.Config.EFFECT_CTRL_KEYDOWN = false;
                //    //console.log("CTRL keyup")
                //});

            },

            AddEffectAudio: function (data, params) {
                var self = this;
                var element = {};

                var entity = Director.Util.getEntity();

                element.directorId = entity.id;
                element.programQipuId = entity.programQipuId;
                element.url = data.httpInnerUrl;
                element.type = 4;
                element.name = params.file.name;
                element.location = '';
                element.extraInfo = '{"volumn":20}';

                element = JSON.stringify(element);

                Director.Dao.addEffect({'data': element}, function (data) {
                    if (data != null && data.code == "A00000") {
                        Director.Util.refreshEffectList(4);
                    }
                })
            },

            AddEffectImage: function (data, params) {
                var self = this;
                var element = Director.Config.EFFECT_DEFAULTS['image'];

                var entity = Director.Util.getEntity();

                element.directorId = entity.id;
                element.programQipuId = entity.programQipuId;
                element.url = data.httpInnerUrl;
                element.type = 1;
                element.name = params.file.name;

                element = JSON.stringify(element);

                Director.Dao.addEffect({'data': element}, function (data) {
                    if (data != null && data.code == "A00000") {
                        Director.Util.refreshEffectList(1);
                    }
                })
            },

            appendEffect: function (data, type) {
                var htmlArr = [];
                var container = null;
                htmlArr.push(Director.Util.makeUpEffectDiv(data, type));


                switch (type) {
                    case 1:
                        container = $("#effect-images");
                        break;
                }

                container.prepend(htmlArr.join(''));
            },

            startUploadFile: function (params, callback) {
                var self = this;
                var url = self.config.EFFECT_UPLOAD_URL;
                url = url + "?t=1";

                $.each(params, function (k, v) {
                    url = url + "&" + k + "=" + v;
                });

                $.ajax({
                    url: url,
                    method: "post",
                    cache: false,
                    contentType: false,
                    processData: false,
                    xhr: function () {
                        var xhr = jQuery.ajaxSettings.xhr();
                        return xhr;
                    },
                    data: params.file,
                    success: function (data) {
                        if (data.code == "A00000") {
                            console.log("success upload");
                            callback.call(this, data.data, params);
                        }
                    },
                    error: function (data) {

                    }
                })
            },

            setProgramPageUrl: function (qipuId) {
                Director.Dao.getProgram({'programQipuId': qipuId}, function (json) {
                    if (json != null && json.code == 'A00000') {
                        var programData = json.data[0];
                        $('span[name=span_program_name]').html('<a target="_blank" href="' + programData.pageUrl + '">' + programData.name + '</a>');
                    } else {
                        console.log('failed to set pageurl')
                    }
                })
            }
        })
    }
);